﻿using System.Collections.Generic;
using System.ServiceModel;
using Ipmce.RemoteVoting.Common.Entities;
using Ipmce.RemoteVoting.Common.Tools.Wcf;

namespace Ipmce.RemoteVoting.Frontend.VotingApplication.Utils
{
	class CandidateListProvider : ICandidateListProvider
	{
		public IList<Candidate> GetCandidateList()
		{
		    try
		    {
                using (var proxy = new ServiceInterfaceProxy<Backend.VotingService.Contract.ICandidateListProvider>("CandidateServiceEndPoint"))
                {
                    return proxy.GetInterface().GetCandidateList();
                }
            }
		    catch (EndpointNotFoundException err)
		    {
		        throw new UnableToProvideCandidateListException("Network error", err);
		    }
		}
	}
}